<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.global.js"></script>
</head>
<body>
    <div id="app">
        <p ref="p">{{count}}</p>
        <p>
            <button @click="count++">count++</button>
        </p>
        <hr>
        <p>
            {{zhang.name}}----{{zhang.age}}---{{zhang.info.height}}
        </p>
        <p>
            <button @click="changeAge">age++</button>
            <br>
            <button @click="zhang.info.height++">height++</button>
            <br>
            <!-- 修改zhang.value -->
            <button @click="zhang = {
                name:'李四',
                age:22,
                info:{
                    height:177,
                    weight:70
                }
            }">重置</button>
        </p>
    </div>
</body>
<script>
    let {createApp,nextTick,getCurrentInstance} = Vue;
    let {ref,reactive,readonly,computed,watch} = Vue;
    let {isRef,isReactive,isProxy,isReadonly} = Vue;
    let {shallowRef,shallowReactive,triggerRef} = Vue;

    // ifRef()   检查某个值是否为 ref。

    var app = createApp({
        
        setup(props) {


            let count = ref(100);
            let doubleCount = computed(()=>{
                count.value * 2;
            })

            
            let addCount = ()=>{
                count.value ++;
            }


            let zhang = shallowRef({
                name:"张三",
                age:18,
                info:{
                    height:173,
                    weight:65
                }
            });  

            let app = getCurrentInstance();  //当前实例 (app)
            let {ctx} = app;  // 获取当前实例 proxy对象(存储数据和方法 计算属性)
            console.log("app",app);

            let changeAge = ()=>{
                zhang.value.age ++
                console.log( zhang.value.age);

                // ctx.$forceUpdate();
                triggerRef(zhang)
            }


            console.log("isRef",isRef(count));
            console.log("isRef",isRef(doubleCount));
            console.log("isRef",isRef(zhang));

            return {
                // 键名: 传递出去的数据名 方法名  计算属性
                count:count,
                doubleCount,
                addCount,
                zhang,
                changeAge,
            }
            
        },
        mounted() {
            // console.log("this",this);
        },
        watch:{
            // "zhang":function(){},
            // "zhang.age":function(){},
        }
        
    })

    app.mount("#app");








</script>
</html>